{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "      <th>ir</th>\n",
       "      <th>lidar</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95819</td>\n",
       "      <td>305</td>\n",
       "      <td>214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95822</td>\n",
       "      <td>299</td>\n",
       "      <td>211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95826</td>\n",
       "      <td>292</td>\n",
       "      <td>199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95829</td>\n",
       "      <td>321</td>\n",
       "      <td>208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95832</td>\n",
       "      <td>298</td>\n",
       "      <td>212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95835</td>\n",
       "      <td>327</td>\n",
       "      <td>212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95838</td>\n",
       "      <td>293</td>\n",
       "      <td>215</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95840</td>\n",
       "      <td>309</td>\n",
       "      <td>218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95843</td>\n",
       "      <td>323</td>\n",
       "      <td>208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95846</td>\n",
       "      <td>292</td>\n",
       "      <td>217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95850</td>\n",
       "      <td>294</td>\n",
       "      <td>215</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95852</td>\n",
       "      <td>323</td>\n",
       "      <td>218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95856</td>\n",
       "      <td>319</td>\n",
       "      <td>218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95858</td>\n",
       "      <td>313</td>\n",
       "      <td>214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95902</td>\n",
       "      <td>298</td>\n",
       "      <td>209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95905</td>\n",
       "      <td>296</td>\n",
       "      <td>211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95908</td>\n",
       "      <td>294</td>\n",
       "      <td>210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95911</td>\n",
       "      <td>314</td>\n",
       "      <td>215</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95914</td>\n",
       "      <td>300</td>\n",
       "      <td>212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95917</td>\n",
       "      <td>324</td>\n",
       "      <td>219</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95920</td>\n",
       "      <td>295</td>\n",
       "      <td>220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95922</td>\n",
       "      <td>320</td>\n",
       "      <td>214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95925</td>\n",
       "      <td>302</td>\n",
       "      <td>211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95928</td>\n",
       "      <td>303</td>\n",
       "      <td>215</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95932</td>\n",
       "      <td>297</td>\n",
       "      <td>215</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95934</td>\n",
       "      <td>306</td>\n",
       "      <td>210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95937</td>\n",
       "      <td>302</td>\n",
       "      <td>217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95940</td>\n",
       "      <td>296</td>\n",
       "      <td>215</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95943</td>\n",
       "      <td>308</td>\n",
       "      <td>213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>20180122</td>\n",
       "      <td>95947</td>\n",
       "      <td>303</td>\n",
       "      <td>211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58958</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115907</td>\n",
       "      <td>297</td>\n",
       "      <td>210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58959</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115910</td>\n",
       "      <td>320</td>\n",
       "      <td>204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58960</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115914</td>\n",
       "      <td>324</td>\n",
       "      <td>205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58961</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115917</td>\n",
       "      <td>302</td>\n",
       "      <td>199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58962</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115919</td>\n",
       "      <td>299</td>\n",
       "      <td>203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58963</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115923</td>\n",
       "      <td>298</td>\n",
       "      <td>206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58964</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115925</td>\n",
       "      <td>301</td>\n",
       "      <td>206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58965</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115929</td>\n",
       "      <td>321</td>\n",
       "      <td>206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58966</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115932</td>\n",
       "      <td>319</td>\n",
       "      <td>209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58967</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115935</td>\n",
       "      <td>311</td>\n",
       "      <td>208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58968</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115938</td>\n",
       "      <td>326</td>\n",
       "      <td>204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58969</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115941</td>\n",
       "      <td>319</td>\n",
       "      <td>206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58970</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115944</td>\n",
       "      <td>303</td>\n",
       "      <td>201</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58971</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115947</td>\n",
       "      <td>323</td>\n",
       "      <td>203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58972</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115950</td>\n",
       "      <td>302</td>\n",
       "      <td>205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58973</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115953</td>\n",
       "      <td>314</td>\n",
       "      <td>202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58974</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115956</td>\n",
       "      <td>326</td>\n",
       "      <td>204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58975</th>\n",
       "      <td>20180124</td>\n",
       "      <td>115959</td>\n",
       "      <td>308</td>\n",
       "      <td>201</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58976</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120002</td>\n",
       "      <td>302</td>\n",
       "      <td>209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58977</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120005</td>\n",
       "      <td>303</td>\n",
       "      <td>207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58978</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120009</td>\n",
       "      <td>310</td>\n",
       "      <td>206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58979</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120012</td>\n",
       "      <td>330</td>\n",
       "      <td>208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58980</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120015</td>\n",
       "      <td>305</td>\n",
       "      <td>205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58981</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120018</td>\n",
       "      <td>301</td>\n",
       "      <td>202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58982</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120021</td>\n",
       "      <td>320</td>\n",
       "      <td>206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58983</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120023</td>\n",
       "      <td>313</td>\n",
       "      <td>208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58984</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120026</td>\n",
       "      <td>297</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58985</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120030</td>\n",
       "      <td>323</td>\n",
       "      <td>204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58986</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120033</td>\n",
       "      <td>326</td>\n",
       "      <td>207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58987</th>\n",
       "      <td>20180124</td>\n",
       "      <td>120036</td>\n",
       "      <td>321</td>\n",
       "      <td>208</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>58988 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           date    time   ir  lidar\n",
       "0      20180122   95819  305    214\n",
       "1      20180122   95822  299    211\n",
       "2      20180122   95826  292    199\n",
       "3      20180122   95829  321    208\n",
       "4      20180122   95832  298    212\n",
       "5      20180122   95835  327    212\n",
       "6      20180122   95838  293    215\n",
       "7      20180122   95840  309    218\n",
       "8      20180122   95843  323    208\n",
       "9      20180122   95846  292    217\n",
       "10     20180122   95850  294    215\n",
       "11     20180122   95852  323    218\n",
       "12     20180122   95856  319    218\n",
       "13     20180122   95858  313    214\n",
       "14     20180122   95902  298    209\n",
       "15     20180122   95905  296    211\n",
       "16     20180122   95908  294    210\n",
       "17     20180122   95911  314    215\n",
       "18     20180122   95914  300    212\n",
       "19     20180122   95917  324    219\n",
       "20     20180122   95920  295    220\n",
       "21     20180122   95922  320    214\n",
       "22     20180122   95925  302    211\n",
       "23     20180122   95928  303    215\n",
       "24     20180122   95932  297    215\n",
       "25     20180122   95934  306    210\n",
       "26     20180122   95937  302    217\n",
       "27     20180122   95940  296    215\n",
       "28     20180122   95943  308    213\n",
       "29     20180122   95947  303    211\n",
       "...         ...     ...  ...    ...\n",
       "58958  20180124  115907  297    210\n",
       "58959  20180124  115910  320    204\n",
       "58960  20180124  115914  324    205\n",
       "58961  20180124  115917  302    199\n",
       "58962  20180124  115919  299    203\n",
       "58963  20180124  115923  298    206\n",
       "58964  20180124  115925  301    206\n",
       "58965  20180124  115929  321    206\n",
       "58966  20180124  115932  319    209\n",
       "58967  20180124  115935  311    208\n",
       "58968  20180124  115938  326    204\n",
       "58969  20180124  115941  319    206\n",
       "58970  20180124  115944  303    201\n",
       "58971  20180124  115947  323    203\n",
       "58972  20180124  115950  302    205\n",
       "58973  20180124  115953  314    202\n",
       "58974  20180124  115956  326    204\n",
       "58975  20180124  115959  308    201\n",
       "58976  20180124  120002  302    209\n",
       "58977  20180124  120005  303    207\n",
       "58978  20180124  120009  310    206\n",
       "58979  20180124  120012  330    208\n",
       "58980  20180124  120015  305    205\n",
       "58981  20180124  120018  301    202\n",
       "58982  20180124  120021  320    206\n",
       "58983  20180124  120023  313    208\n",
       "58984  20180124  120026  297    200\n",
       "58985  20180124  120030  323    204\n",
       "58986  20180124  120033  326    207\n",
       "58987  20180124  120036  321    208\n",
       "\n",
       "[58988 rows x 4 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd    ###dataread###（1〜4行目と出力の上5行くらいを図示）\n",
    "data  = pd.read_csv(\"sensor_data_200.txt\", delimiter=\" \", \n",
    "                    header=None, names = (\"date\",\"time\",\"ir\",\"lidar\"))\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "平均: 209.737132976\n",
      "不偏分散: 23.4081065986\n"
     ]
    }
   ],
   "source": [
    "from scipy.stats import norm\n",
    "import math\n",
    "\n",
    "mu = data[\"lidar\"].mean()\n",
    "var = data[\"lidar\"].var()\n",
    "\n",
    "print(\"平均:\",mu)\n",
    "print(\"不偏分散:\",var)\n",
    "\n",
    "p = norm(loc=mu, scale=math.sqrt(var))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "標本数3\n",
      "標本分散の平均: 15.5235156872\n",
      "不偏分散の平均: 23.3103535561\n",
      "標本数1000\n",
      "標本分散の平均: 23.3720879125\n",
      "不偏分散の平均: 23.4024375646\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "def sampling(n):\n",
    "    return p.rvs(size=n)\n",
    "\n",
    "def sampling_var(n): #n個サンプリングして標本分散を返す関数\n",
    "    return np.var( sampling(n) ) \n",
    "\n",
    "def unbiased_var(n): #n個サンプリングして不偏分散を返す関数\n",
    "    return np.var( sampling(n) , ddof=1) \n",
    "\n",
    "print(\"標本数3\")\n",
    "print(\"標本分散の平均:\", np.mean([sampling_var(3) for i in range(10000)]))\n",
    "print(\"不偏分散の平均:\", np.mean([unbiased_var(3) for i in range(10000)]))\n",
    "\n",
    "print(\"標本数1000\")\n",
    "print(\"標本分散の平均:\", np.mean([sampling_var(1000) for i in range(10000)]))\n",
    "print(\"不偏分散の平均:\", np.mean([unbiased_var(1000) for i in range(10000)]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
